﻿using System;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using RayD.Core;

namespace RayD.Repository.Entites.SystemModule
{
    [Table("BASE_ROLE")]
    public class RoleEntity
    {
        #region 实体成员
        /// <summary>
        /// 角色主键
        /// </summary>
        /// <returns></returns>
        [Key]
        [Column("B_ROLEID")]
        public string B_RoleId { get; set; }
        /// <summary>
        /// 所属架构
        /// </summary>
        /// <returns></returns>
        [Column("B_MANAFRAMEID")]
        public string B_ManaframeId { get; set; }
        /// <summary>
        /// 角色编码
        /// </summary>
        /// <returns></returns>
        [Column("B_ENCODE")]
        public string B_EnCode { get; set; }
        /// <summary>
        /// 角色名称
        /// </summary>
        /// <returns></returns>
        [Column("B_FULLNAME")]
        public string B_FullName { get; set; }
        /// <summary>
        /// 排序码
        /// </summary>
        /// <returns></returns>
        [Column("B_SORTCODE")]
        public int? B_SortCode { get; set; }
        /// <summary>
        /// 有效标志
        /// </summary>
        /// <returns></returns>
        [Column("B_ENABLEDMARK")]
        public EnabledMark? B_EnabledMark { get; set; }
        /// <summary>
        /// 备注
        /// </summary>
        /// <returns></returns>
        [Column("B_DESCRIPTION")]
        public string B_Description { get; set; }
        /// <summary>
        /// 创建日期
        /// </summary>
        /// <returns></returns>
        [Column("B_CREATEDATE")]
        public DateTime? B_CreateDate { get; set; }
        /// <summary>
        /// 创建用户主键
        /// </summary>
        /// <returns></returns>
        [Column("B_CREATEUSERID")]
        public string B_CreateUserId { get; set; }
        /// <summary>
        /// 创建用户
        /// </summary>
        /// <returns></returns>
        [Column("B_CREATEUSERNAME")]
        public string B_CreateUserName { get; set; }
        /// <summary>
        /// 修改日期
        /// </summary>
        /// <returns></returns>
        [Column("B_MODIFYDATE")]
        public DateTime? B_ModifyDate { get; set; }
        /// <summary>
        /// 修改用户主键
        /// </summary>
        /// <returns></returns>
        [Column("B_MODIFYUSERID")]
        public string B_ModifyUserId { get; set; }
        /// <summary>
        /// 修改用户
        /// </summary>
        /// <returns></returns>
        [Column("B_MODIFYUSERNAME")]
        public string B_ModifyUserName { get; set; }
        #endregion

        #region 扩展操作
        /// <summary>
        /// 新增调用
        /// </summary>
        public void Create()
        {
            if (this.B_EnabledMark.IsEmpty())
            {
                this.B_EnabledMark = EnabledMark.Enabled;
            }
            this.B_RoleId = Guid.NewGuid().ToString();
            this.B_CreateDate = DateTime.Now.ToCstTime();
            UserInfo userInfo = AuthenticationHelper.LoginUserInfo;
            this.B_CreateUserId = userInfo.userId;
            this.B_CreateUserName = userInfo.realName;
        }
        /// <summary>
        /// 编辑调用
        /// </summary>
        public void Modify()
        {
            this.B_ModifyDate = DateTime.Now.ToCstTime();
            UserInfo userInfo = AuthenticationHelper.LoginUserInfo;
            this.B_ModifyUserId = userInfo.userId;
            this.B_ModifyUserName = userInfo.realName;
        }
        #endregion

        #region 扩展属性
        /// <summary>
        /// 架构名称
        /// </summary>
        [NotMapped]
        public string ManaframeName { get; set; } 
        #endregion
    }
}
